package com.tools.web.interceptor.auth;

import com.tools.common.object.Note;

import java.util.Objects;

/**
 * 从缓存中获取 AuthUser 后的包装类，主要是方便判断是否可以为 AuthToken 续期
 * */
@Note("从缓存中获取 AuthUser 后的包装类，主要是方便判断是否可以为 AuthToken 续期")
public final class GetAuthUserResult {

    @Note("是否允许续期")
    private final boolean canExtend;

    @Note("AuthUser 对象")
    private final AuthUser authUser;

    public GetAuthUserResult(final boolean canExtend, final AuthUser authUser) {
        this.canExtend = canExtend;
        this.authUser = authUser;
    }


    public boolean isCanExtend() {
        return canExtend;
    }

    public AuthUser getAuthUser() {
        return authUser;
    }

    public boolean authUserIsNull() {
        return authUser == null;
    }

    @Override
    public String toString() {
        return "GetAuthUserResult{" +
                "canExtend=" + canExtend +
                ", authUser=" + authUser +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        GetAuthUserResult that = (GetAuthUserResult) o;
        return canExtend == that.canExtend && Objects.equals(authUser, that.authUser);
    }

    @Override
    public int hashCode() {
        return Objects.hash(canExtend, authUser);
    }
}
